home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacFormat España 15
/
macformat_15.iso
/
Shareware Internet
/
Ciencia
/
CFG 2.3 (Shareware)
/
µCinema Converter
/
µCinema.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-03
|
6KB
|
278 lines
/********************************************************************
µCinema Converter 1.0
module: µCinema.c
April 1994
by John A. Schlack
********************************************************************/
#include <GestaltEqu.h>
#include <Movies.h>
#include <size_t.h>
#include "apple events.h"
#include "constants.h"
#include "events.h"
#include "menu bar.h"
#include "PICS to QuickTime.h"
#include "preferences.h"
#include "pstring.h"
#include "µCinema.h"
/* --------------------------------------------------------------------------------- */
#define ICON_ALERT_ID 500
#define NO_ICON_ALERT_ID 501
#define ERROR_STRING_SET 500
enum DISPLAY_SEVERITY { ALRT_ALERT, ALRT_NOTE, ALRT_CAUTION, ALRT_STOP };
/* --------------------------------------------------------------------------------- */
static unsigned short pgmStatus;
static unsigned char errUnknown[] = "\pAn unknown error has occurred. Quitting...";
/* --------------------------------------------------------------------------------- */
/* Private Function Prototypes */
void main( void );
static void toolboxInit( void );
static Boolean verifyEnvironment( void );
static void globalInit( void );
static void messageAlert( unsigned char * msg, short alert_type );
/* --------------------------------------------------------------------------------- */
void main( void )
{
toolboxInit();
globalInit();
if (!verifyEnvironment())
ExitToShell();
loadPreferences();
menuBarInit();
if (!loadDragAndDrop())
{
while (!(programStatus( PS_APP_DONE ) && programStatus( PS_LAST_EVENT_NULL )))
doEvents();
}
if (programStatus( PS_PREFS_DIRTY ))
savePreferences();
ExitToShell();
}
/* --------------------------------------------------------------------------------- */
static void toolboxInit( void )
{
MoreMasters();
InitGraf( &thePort );
InitFonts();
InitWindows();
InitMenus();
TEInit();
InitDialogs( nil );
InitCursor();
FlushEvents( everyEvent - diskMask - app4Mask, 0 );
}
/* --------------------------------------------------------------------------------- */
/*
static Boolean verifyEnvironment( void )
Description:
This function checks to see that the System has certain features installed.
System 7 and QuickTime are mandatory. Apple Events are required to support
drag and drop.
Input:
none
Output:
none
Globals / Regionals Modified:
none
Returns:
True if program can proceed or false to abort.
*/
static Boolean verifyEnvironment( void )
{
long response;
short err = 0;
Boolean gestaltAvail;
#define GestaltTrap 0xA1AD
#define UnImpltrap 0xA89F
gestaltAvail = ( NGetTrapAddress( GestaltTrap, OSTrap ) !=
NGetTrapAddress( UnImpltrap, OSTrap ) );
if (!gestaltAvail)
{
errorHandler( ERR_NO_GESTALT );
return false;
}
if (Gestalt( gestaltSystemVersion, &response ) != noErr)
err = ERR_GESTALT_FAILED;
else if (response < 0x0700)
err = ERR_NO_SYSTEM7;
if (err)
{
errorHandler( err );
return false;
}
/* QuickTime */
if (Gestalt( gestaltQuickTime, &response ) != noErr)
{
errorHandler( ERR_NO_QUICKTIME );
return false;
}
/* FSSpec */
if (Gestalt( gestaltFSAttr, &response ) != noErr)
err = ERR_NO_FSSPEC;
else if (!(response & (1 << gestaltHasFSSpecCalls)))
err = ERR_NO_FSSPEC;
if (err)
{
errorHandler( err );
return false;
}
/* Apple Events */
if (Gestalt( gestaltAppleEventsAttr, &response ) != noErr)
{
if (response & (1 << gestaltAppleEventsPresent))
installProgramStatus( PS_APPLE_EVENTS );
}
return true;
}
/* --------------------------------------------------------------------------------- */
static void globalInit( void )
{
pgmStatus = 0;
}
/* --------------------------------------------------------------------------------- */
void errorHandler( short stringNum )
{
Str255 mPtr;
GetIndString( &(mPtr[0]), ERROR_STRING_SET, stringNum );
if (*mPtr)
messageAlert( mPtr, ALRT_CAUTION );
else
messageAlert( errUnknown, ALRT_CAUTION );
}
/* --------------------------------------------------------------------------------- */
void errorHandlerParameter( short stringNum, unsigned char * message )
{
Str255 mPtr;
GetIndString( &(mPtr[0]), ERROR_STRING_SET, stringNum );
if (*mPtr)
{
pstrsub( mPtr, message );
messageAlert( mPtr, ALRT_CAUTION );
}
else
messageAlert( errUnknown, ALRT_CAUTION );
}
/* --------------------------------------------------------------------------------- */
static void messageAlert( unsigned char * msg, short alert_type )
{
short alert_id;
ParamText( msg, nil, nil, nil );
alert_id = (alert_type == ALRT_ALERT) ? NO_ICON_ALERT_ID : ICON_ALERT_ID;
switch( alert_type )
{
case ALRT_ALERT:
Alert( NO_ICON_ALERT_ID, nil );
break;
case ALRT_NOTE:
NoteAlert( ICON_ALERT_ID, nil );
break;
case ALRT_STOP:
StopAlert( ICON_ALERT_ID, nil );
break;
case ALRT_CAUTION:
default:
CautionAlert( ICON_ALERT_ID, nil );
break;
}
}
/* --------------------------------------------------------------------------------- */
void installProgramStatus( short pgmBit )
{
pgmStatus |= (1 << pgmBit);
}
/* --------------------------------------------------------------------------------- */
Boolean programStatus( short pgmBit )
{
return ((pgmStatus & (1 << pgmBit)) ? true : false);
}
/* --------------------------------------------------------------------------------- */
void alterProgramStatus( short pgmBit, Boolean setBit )
{
unsigned short mask = 1 << pgmBit;
if (setBit)
pgmStatus |= mask;
else
pgmStatus &= (~mask);
}